package com.lottery.utils.messageTube;

import com.lottery.dao.qiuqiu.statisticsDao.AgencyDao;
import com.lottery.dto.MessageTube;
import com.lottery.entity.Agency;
import com.lottery.initData.InitData;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class MessageFactory {
	@Resource
	private AgencyDao agencyDao;

	//渠道商信息通道模版
	private Map<String, MessageTube> messagePlate(){
		MessageTube sscBetMessageTobe = new MessageTube();//投注信息管道
		MessageTube sscBarMessageTobe = new MessageTube();//聊天信息管道
		Map<String,MessageTube> map = new HashMap<>();
		//1bet:ssc下注信息通道,1bar:目前为其他
		map.put("1bet",sscBetMessageTobe);
		map.put("1bar",sscBarMessageTobe);
		map.put("3bet",sscBetMessageTobe);
		map.put("3bar",sscBarMessageTobe);
		return map;
	}

	//渠道商信息发布通道factory
	public void InitMessagetube(){
		//初始化之前清空所有的通道信息
		InitData.MESSAGE_GROUP.clear();
		InitData.ONLINE_MAP.clear();
		List<Agency> agencies = agencyDao.selectAllAgency();
		for(Agency agency :agencies){
			String agencyId = agency.getId();
			Map<String, MessageTube> stringMessageTubeMap = messagePlate();

			//消息通道
			InitData.MESSAGE_GROUP.put(agencyId,stringMessageTubeMap);
			
			//初始化机器人在线数目
			InitData.ROBOT_ONLINE_NUM.put(agencyId,0);

			Map<Integer,Long> map = new HashMap<>();

			//用户在线人数
			InitData.ONLINE_MAP.put(agencyId,map);
		}
	}
}
